package com.woniuxy.service.impl;

import com.woniuxy.dao.RbacRoleDao;
import com.woniuxy.entity.RbacRole;
import com.woniuxy.service.RbacRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


/**
 * service业务层代码，用于调用dao层接口
 */
@Service
public class RbacRoleServiceImpl implements RbacRoleService {
    @Autowired
    private RbacRoleDao rbacRoleDao;
    @Transactional
    @Override
    public int createOne(RbacRole rbacRole) {
        //额外的具体业务代码
        int i = rbacRoleDao.insertOne(rbacRole);
        int i1 = removeOne(35);//代码执行到这一步后，会停在这里 先执行完removeOne成功以后，才能继续下去
        return i;
    }
    @Override
    public int removeOne(int id) {
        int i = rbacRoleDao.deleteOne(id);
        i = 1/0;// 这里会报 / by zero的错 ，来演示事务的原子性
        return i;
    }
    @Override
    public int updateOne(RbacRole rbacRole) {
        return rbacRoleDao.updateOne(rbacRole);
    }

    @Override
    public RbacRole findOne(int id) {
        return rbacRoleDao.findOne(id);
    }

    @Override
    public List<Map<String, String>> findAll() {
        return rbacRoleDao.findAll();
    }

    @Override
    public List<RbacRole> findAllByObject() {
        return rbacRoleDao.findAllByObject();
    }

    @Override
    public List<RbacRole> search(RbacRole rbacRole) {
        return rbacRoleDao.search(rbacRole);
    }

}
